﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace GameWP
{
    public class BowZombie : AutoCharacter
    {
    #region  Initiation
        public BowZombie(List<Texture2D> listTextures,
            Vector2 posotion,
            Vector2 positionBullet,
            int hp,
            int damage,
            float speed,
            float zoneAttack,
            float delay,
            float scaleTexture,
            int price,
            SpriteEffects spriteEffect,
            List<List<int>> seqTexture)
            : base(listTextures, posotion, hp, damage, speed, delay, scaleTexture, price, spriteEffect, seqTexture)          
        {
            _listTextures = listTextures;
            _position = posotion;
            _positionBullet = positionBullet;
            _hp = hp; _hpmax = _hp;
            _damage = damage;
            _speed = speed; _speedmax = _speed;
            _scaleRect = zoneAttack;
            _delay = delay;
            _price = price;
            _seqTexture = seqTexture;
            _rectangle = new Rectangle
                ((int)_position.X, (int)_position.Y, _listTextures[0].Width, _listTextures[0].Height);
            _scaleTexture = scaleTexture;
            _spriteEffect = spriteEffect;
            _indexTexture = 0;
            _state = State.Move;
            _preState = State.Unknow;
            
            //HpBar
            _hpBar = new HpBar(_hp, new Vector2(_position.X + 200, _position.Y - 20), Color.Red);   
        
            //Arrow
            _arrow = new Arrow(_listTextures[_listTextures.Count - 1 ],InitPositionArrow(), _speed, _spriteEffect, _scaleTexture);
        }    
    #endregion

    #region  Methods
        private Vector2 InitPositionArrow()
        {
            return new Vector2(_position.X, _positionBullet.Y);
        }

        public override bool IsCollisionWith(Sprite2D AnotherSprite)
        {
            if (this._state == State.Fight)
            {
                if (CharacterWasHit.IsOnlyCollisionWith(_arrow))
                    _arrow.Position = InitPositionArrow();
                if (_arrow.Position.X < -0 || _arrow.Position.X > 2048)
                    _arrow.Position = InitPositionArrow();
                if (CharacterWasHit.IsOnlyCollisionWith(this))
                    _arrow.ScaleTexture = 0;
                else _arrow.ScaleTexture = _scaleTexture;
            }
            if (this._state == State.Move)
                CharacterWasHit = null;
            if (CharacterWasHit != null)
                if (CharacterWasHit.Position.X > this.Position.X)
                    return false;
            return base.IsCollisionWith(AnotherSprite);
        }
    #endregion

    #region Update & Draw
        public override void Update(GameTime gametime, Vector2 position)
        {
            base.Update(gametime, position);
            if (_state == State.Fight)
            {
                _arrow.Update(gametime, Vector2.Zero);
               // if (_indexTexture == _seqTexture[(int)_state][_seqTexture[(int)_state].Count - 1])
                   // _arrow.Position = InitPositionArrow();
            }
        }

        public override void Draw(SpriteBatch spritebatch, GameTime gametime)
        {
            base.Draw(spritebatch, gametime);
            if (_state == State.Fight)
                _arrow.Draw(spritebatch, gametime);
        }
    #endregion
    
    }
}
